package com.kehutong.payfees.service.treasure;

//import com.kehutong.payfees.entity.treasure.PersonalTempSeal;
//import com.kehutong.payfees.util.ESignTreasureUrlConfig;
//import org.coraframework.inject.Inject;
//import org.coraframework.json.JSONObject;
//import org.coraframework.mvc.webservice.WebService;
//import org.coraframework.orm.Pool;
//import org.coraframework.orm.jdbc.SQLSession;
//
//@WebService("/sign/treasure/personal/seal")
//public class ESignTreasurePersonalTempSealServiceImpl {
//
//    @Inject
//    protected SQLSession jdbcSession;
//
//    @Inject
//    private ESignTreasureOAuthServiceImpl eSignTreasureOAuthService;
//
//    @Inject
//    private ESignTreasureUrlConfig eSignTreasureUrlConfig;
//
//    public Object pagePersonalTempSeal(JSONObject jsonObject) {
//        return jdbcSession.findPage(PersonalTempSeal.class)
//                .eq(jsonObject, "alias", "accountName")
//                .eq("deleted", false)
//                .page(jsonObject).exe();
//    }
//
//    public void createPersonalTempSeal(PersonalTempSeal personalTempSeal) throws Exception {
//        JSONObject jsonObject = eSignTreasureUrlConfig.postESignTreasure("/v1/accounts/" + personalTempSeal.getAccountId() + "/seals/personaltemplate", (http) -> {
//            JSONObject bodyParams = new JSONObject();
//            bodyParams.put("alias", personalTempSeal.getAlias());
//            bodyParams.put("color", personalTempSeal.getColor());
//            bodyParams.put("type", personalTempSeal.getType());
//            http.setBody(bodyParams.toString());
//
//            eSignTreasureOAuthService.setRequestHeaderValue(http);
//        });
//
//        String fileId = eSignTreasureOAuthService.getFileId(jsonObject.getString("url"), personalTempSeal.getAlias() + ".png");
//        personalTempSeal.setFileId(fileId);
//        personalTempSeal.setFileKey(jsonObject.getString("fileKey"));
//        personalTempSeal.setSealId(jsonObject.getString("sealId"));
//        jdbcSession.insert(personalTempSeal);
//    }
//
//    public Object getPersonalTempSeal(String id) {
//        return Pool.get(PersonalTempSeal.class, id);
//    }
//
//    public void deletePersonalTempSeal(String accountId, String sealId) throws Exception {
//        JSONObject jsonObject = eSignTreasureUrlConfig.delete("/v1/accounts/" + accountId + "/seals/" + sealId, (http) -> {
//            eSignTreasureOAuthService.setRequestHeaderValue(http);
//        });
//
//        PersonalTempSeal personalTempSeal = jdbcSession.findOne(PersonalTempSeal.class)
//                .eq("sealId", sealId)
//                .eq("deleted", false).exe();
//        personalTempSeal.setDeleted(true);
//        jdbcSession.updateById(personalTempSeal);
//    }
//}
